//
//  SCNCenterHeaderView.swift
//  ShoucainuSwift
//
//  Created by 王家旭 on 2017/3/28.
//  Copyright © 2017年 Riluee. All rights reserved.
//

import UIKit

class SCNCenterHeaderView: UIView {
    //
    lazy var topBGView: UIView = {
        let topBGView = UIView()
        topBGView.backgroundColor = SCNConstants.rootBackgroundColor
        return topBGView
    }()
    //头像
    lazy var headImgView: UIImageView = {
       
        let imgView = UIImageView(image: UIImage(named:"account_placeholder_head"))
        imgView.layer.cornerRadius = 35
        imgView.layer.borderWidth = 2.0
        imgView.layer.borderColor = SCNConstants.colorWithHexString("86dbff").cgColor
        return imgView
    }()
    //名字
    lazy var nameL: UILabel = {
        let lab = UILabel()
        lab.textColor = .white
        lab.font = UIFont.systemFont(ofSize: 11.0)
        lab.textAlignment = .center
        lab.text = "王大哥"
        return lab
    }()
    //余额
    lazy var balanceL: UILabel = {
        let lab = UILabel()
        lab.textColor = .white
        lab.font = UIFont.boldSystemFont(ofSize: 20.0)
        lab.textAlignment = .center
        lab.text = "10.33"
        return lab
    }()
    //可用余额(元)
    lazy var balanceTextL: UILabel = {
        let lab = UILabel()
        lab.textColor = .white
        lab.font = UIFont.systemFont(ofSize: 14.0)
        lab.textAlignment = .center
        lab.text = "可用余额(元)"
        return lab
    }()
    //白色背景框
    lazy var whiteImgView: UIImageView = {
        let imgView = UIImageView(image: UIImage(named:"account_head_BG"))
        return imgView
    }()
    lazy var whiteHorizontalLine: UIView = {
        let view = UIView()
        view.backgroundColor = SCNConstants.colorWithHexString("eaeaea")
        return view
    }()
    lazy var whiteVerticalLine: UIView = {
        let view = UIView()
        view.backgroundColor = SCNConstants.colorWithHexString("eaeaea")
        return view
    }()
    //
    lazy var centerView: UIView = {
        let centerView = UIView()
        centerView.backgroundColor = .white
        return centerView
    }()
    //
    lazy var centerLink: UIView = {
        let centerLink = UIView()
        centerLink.backgroundColor = SCNConstants.tableViewBackgroundColor
        return centerLink
    }()
    
    //充值
    lazy var recharge: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("充值", for: .normal)
        btn.setTitleColor(SCNConstants.rootBackgroundColor, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16.5)
        btn.setImage(UIImage(named:"account_menus_icon_rechage"), for: .normal)
        btn.titleEdgeInsets.right = -10
        return btn
    }()
    //提现
    lazy var withdraw: UIButton = {
        let btn = UIButton(type: .custom)
        btn.setTitle("提现", for: .normal)
        btn.setTitleColor(SCNConstants.rootBackgroundColor, for: .normal)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 16.5)
        btn.setImage(UIImage(named:"account_menus_icon_pastal"), for: .normal)
        btn.titleEdgeInsets.right = -10
        return btn
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = SCNConstants.tableViewBackgroundColor
        
        
        configurationUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        topBGView.snp.makeConstraints { (make) in
            make.leading.trailing.top.equalToSuperview()
            make.height.equalTo(305)
        }
        headImgView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 70, height:70))
            make.centerX.equalToSuperview();
            make.top.equalTo(45)
        }
        nameL.snp.makeConstraints { (make) in
            make.top.equalTo(headImgView.snp.bottom).offset(10)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(20)
        }
        balanceL.snp.makeConstraints { (make) in
            make.top.equalTo(nameL.snp.bottom).offset(5)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(20)
        }
        balanceTextL.snp.makeConstraints { (make) in
            make.top.equalTo(balanceL.snp.bottom).offset(2)
            make.leading.trailing.equalToSuperview()
            make.height.equalTo(20)
        }
        whiteImgView.snp.makeConstraints { (make) in
            make.bottom.equalTo(topBGView).offset(1)
            make.leading.equalTo(15)
            make.trailing.equalTo(-15)
            make.height.equalTo(100)
        }
        whiteHorizontalLine.snp.makeConstraints { (make) in
            make.leading.trailing.centerY.equalToSuperview()
            make.height.equalTo(0.5)
        }
        whiteVerticalLine.snp.makeConstraints { (make) in
            make.centerX.top.bottom.equalToSuperview()
            make.width.equalTo(0.5)
        }
        centerView.snp.makeConstraints { (make) in
            make.top.equalTo(315)
            make.height.equalTo(45)
            make.leading.equalTo(10)
            make.trailing.equalTo(-10)
        }
        centerLink.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.height.equalTo(45)
            make.width.equalTo(5)
            make.centerX.equalToSuperview()
        }
        
        recharge.snp.remakeConstraints { (make) in
            make.leading.top.equalTo(0)
            make.height.equalTo(45)
            make.width.equalTo(self.frame.size.width/2 - 12.5)
        }
        withdraw.snp.remakeConstraints { (make) in
            make.trailing.top.equalTo(0)
            make.height.equalTo(45)
            make.width.equalTo(self.frame.size.width/2 - 12.5)
        }
    }
    
    func configurationUI() {
        
        //let topBGView = UIView(frame: CGRect(x: 0, y: 0, width: SCNConstants.SCREENWIDTH, height: 305))
        //topBGView.backgroundColor = SCNConstants.colorWithHexString("2588e5")
        addSubview(topBGView)
        topBGView.addSubview(headImgView)
        topBGView.addSubview(nameL)
        topBGView.addSubview(balanceL)
        topBGView.addSubview(balanceTextL)
        topBGView.addSubview(whiteImgView)
        whiteImgView.addSubview(whiteVerticalLine)
        whiteImgView.addSubview(whiteHorizontalLine)
        
        
        
        //let centerView = UIView(frame: CGRect(x: 10, y: 315, width: SCNConstants.SCREENWIDTH - 20, height: 45))
        //centerView.backgroundColor = .white
        addSubview(centerView)
        
        //let centerLink = UIView(frame: CGRect(x: (SCNConstants.SCREENWIDTH - 20)/2 - 2.5, y: 0, width: 5, height: 45))
        //centerLink.backgroundColor = backgroundColor
        centerView.addSubview(centerLink)
        
        
        centerView.addSubview(recharge)
        centerView.addSubview(withdraw)
        
        
    }

}
